package view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

public class RegisterView extends JFrame {
    private final JTextField usernameField;
    private final JPasswordField passwordField;
    private final JCheckBox adminCheckBox;
    private final JButton registerButton;
    private final JButton backButton;

    public RegisterView() {
        setTitle("用户注册");
        setSize(300, 250);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setLayout(new GridLayout(5, 2, 5, 5));

        add(new JLabel("用户名:"));
        usernameField = new JTextField();
        add(usernameField);

        add(new JLabel("密码:"));
        passwordField = new JPasswordField();
        add(passwordField);

        add(new JLabel("管理员:"));
        adminCheckBox = new JCheckBox();
        add(adminCheckBox);

        registerButton = new JButton("注册");
        add(registerButton);

        backButton = new JButton("返回登录");
        add(backButton);
    }

    // Getters
    public String getUsername() { return usernameField.getText(); }
    public String getPassword() { return new String(passwordField.getPassword()); }
    public boolean isAdmin() { return adminCheckBox.isSelected(); }

    // 添加监听器
    public void addRegisterListener(ActionListener listener) {
        registerButton.addActionListener(listener);
    }

    public void addBackListener(ActionListener listener) {
        backButton.addActionListener(listener);
    }
}